package abc.hd.com.connacta;

import abc.hd.com.entity.bookes;
import abc.hd.com.entity.bookuser;
import abc.hd.com.ggl.DateUtil;
import abc.hd.com.sersiona.aer;
import abc.hd.com.sersiona.sersiona.aerimpl;
import com.alibaba.druid.sql.visitor.functions.If;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
@RequestMapping("/qk")
public class caas extends HttpServlet {
    @Autowired
    private aer aa;

    @RequestMapping("/zs")
    public String zc(Model model,@RequestParam(defaultValue = "1") Integer pageindex){
        PageInfo<bookes> queryall = aa.queryall (pageindex);
        model.addAttribute ("aab",queryall);
        return "index";
    }
    @RequestMapping("zc")
    public String zc(){
        return "zc";
    }
    @RequestMapping("/fh")
    public String fh(){
        return "dngl";
    }

    @RequestMapping("/dl")
    public String dl(Model model,String yhm,String mm){
        bookuser getonedata = aa.getonedata (yhm, mm);
        if (getonedata!=null) {
            System.out.println (1);
            model.addAttribute ("msg",getonedata);
            return "forward:/qk/zs";
        }else {
            return "redirect:/qk/fh";
        }
    }
    @RequestMapping("/add")
    public String add(bookuser bookuser){
        int adddata = aa.adddata (bookuser);
        if (adddata>0) {
            return "dngl";
        }else{
            return "zc";
        }
    }
    @RequestMapping("/updata")
    public String updata(int id){
        bookes querydata = aa.querydata(id);
        if (querydata.getIs_borrow ()==0) {
            aa.updatadata(1,id);
        }else if(querydata.getIs_borrow ()==1){
            aa.updatadata (0,id);
        }
        return "forward:/qk/zs";
    }
}
